import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { HttpServicesProvider } from "../../providers/http-services/http-services";
import { ValidateProvider } from "../../providers/validate/validate";
import { StorageProvider } from "../../providers/storage/storage";

@IonicPage({
    segment:'member/my_message/detail',
    defaultHistory:['MemberPage']
})
@Component({
    selector: 'page-person-my-message-detail',
    templateUrl: 'person-my-message-detail.html',
})
export class PersonMyMessageDetailPage {
    id = 0;
    infoData = {};
    constructor(
        public navCtrl: NavController,
        public navParams: NavParams,
        public httpService:HttpServicesProvider,
        public storage:StorageProvider,
        public validate:ValidateProvider
    ) {
        if (!this.validate.checkLogin()) {
            this.navCtrl.push('LoginPage');
        }
    }
    ionViewCanEnter(){
        return this.validate.checkLogin();
    }

    ionViewWillEnter(){
        if(!this.validate.checkLogin()){//登录
            this.navCtrl.push('LoginPage',{'backPage':'MemberPage'});
        }else{
            //文章ID
            this.id = this.navParams.get('id');
            this.getData();
        }
    }

    getData(){
        let tokenInfo = JSON.parse(this.storage.get('tokenInfo'));
        let token = tokenInfo['token'];

        let apiUrl = "/message/my_message_detail/token/"+token+"/id/"+this.id;
        this.httpService.requestData(apiUrl,(response) => {
            //全部数据
            this.infoData = response['data'];

        });
    }
}
